import sys
import zmq
from bstar import BinaryStar


def echo(socket, msg):
    socket.send_multipart(msg)


def main():
    if '-p' in sys.argv:
        star = BinaryStar(True, "tcp://*:5003", "tcp://localhost:5004")
        star.register_voter("tcp://*:5001", zmq.ROUTER, echo)
    elif '-b' in sys.argv:
        star = BinaryStar(False, "tcp://*:5004", "tcp://localhost:5003")
        star.register_voter("tcp://*:5002", zmq.ROUTER, echo)
    else:
        print("Usage: bstarsrv2.py {-p | -b}")
        return
    star.start()


if __name__ == "__main__":
    main()
